#LANG=C
SRC_PATH=./src
BIN_PATH=../bin
INC_PATH=-I. -I../include
LIB_PATH=-L../lib
SHRLIB_PATH = ../lib

LIB= -lpthread -lstdc++ -lm -lrt -llpsys -lprotobuf -lphxrpc 
SHRLIB = $(SHRLIB_PATH)/libprotobuf-lite.so \
		 $(SHRLIB_PATH)/libprotobuf.so    \
		 $(SHRLIB_PATH)/libprotoc.so    \
		 $(SHRLIB_PATH)/liblpsys.so
STLIB = ../lib/libphxrpc.a ../lib/libprotobuf.a ../lib/libprotoc.a

CC=gcc
CPPFLAGS=-std=c++11 -Wall -D_REENTRANT -D_GNU_SOURCE -D_XOPEN_SOURCE -fPIC -m64 -g2

OBJS = click.pb.o pc_advertisement_client.o pc_advertisement_server_config.o pc_advertisement_service_impl.o phxrpc_pc_advertisement_dispatcher.o \
	   phxrpc_pc_advertisement_service.o phxrpc_pc_advertisement_stub.o pc_advertisement_tool_impl.o phxrpc_pc_advertisement_tool.o 

INDEX_OBJS = 

all: clean compile pc_advertisement_tool_main  pc_advertisement_main 

compile:
	$(CC) $(CPPFLAGS) $(INC_PATH) $(LIB_PATH) -c click.pb.cc -o click.pb.o
	$(CC) $(CPPFLAGS) $(INC_PATH) $(LIB_PATH) -c pc_advertisement_client.cpp -o pc_advertisement_client.o
	$(CC) $(CPPFLAGS) $(INC_PATH) $(LIB_PATH) -c pc_advertisement_server_config.cpp -o pc_advertisement_server_config.o
	$(CC) $(CPPFLAGS) $(INC_PATH) $(LIB_PATH) -c phxrpc_pc_advertisement_dispatcher.cpp -o phxrpc_pc_advertisement_dispatcher.o
	
	$(CC) $(CPPFLAGS) $(INC_PATH) $(LIB_PATH) -c pc_advertisement_service_impl.cpp -o pc_advertisement_service_impl.o
	$(CC) $(CPPFLAGS) $(INC_PATH) $(LIB_PATH) -c phxrpc_pc_advertisement_service.cpp -o phxrpc_pc_advertisement_service.o
	$(CC) $(CPPFLAGS) $(INC_PATH) $(LIB_PATH) -c phxrpc_pc_advertisement_stub.cpp -o phxrpc_pc_advertisement_stub.o
	$(CC) $(CPPFLAGS) $(INC_PATH) $(LIB_PATH) -c phxrpc_pc_advertisement_tool.cpp -o phxrpc_pc_advertisement_tool.o
	$(CC) $(CPPFLAGS) $(INC_PATH) $(LIB_PATH) -c pc_advertisement_tool_impl.cpp -o pc_advertisement_tool_impl.o
	
pc_advertisement_tool_main:
	$(CC) $(CPPFLAGS) $(INC_PATH) $(LIB_PATH) $(SHRLIB) $(LIB) -Wl,-rpath=$(SHRLIB_PATH) $(OBJS) $(STLIB) pc_advertisement_tool_main.cpp -o pc_advertisement_tool_main 
#	$(CC) $(CPPFLAGS) $(INC_PATH) $(LIB_PATH) $(SHRLIB) $(LIB) -Wl,-rpath=$(SHRLIB_PATH) $(OBJS) $(STLIB) pc_advertisement_tool_main.cpp -o $(BIN_PATH)/pc_advertisement_tool_main 
#	$(CC) $(CPPFLAGS) $(INC_PATH) $(OBJS) -Wl,-rpath=$(SHRLIB_PATH) $(STLIB) pc_advertisement_tool_main.cpp $(LIB_PATH) $(SHRLIB) $(LIB) -o pc_advertisement_tool_main 
	#mv $@ $(BIN_PATH)
	#rm -f *.o 
	@printf "\033[32m pc_advertisement_tool_main SUCCESS \033[0m\n"


pc_advertisement_main:
	$(CC) $(CPPFLAGS) $(INC_PATH) $(OBJS) -Wl,-rpath=$(SHRLIB_PATH) $(STLIB) pc_advertisement_main.cpp $(LIB_PATH) $(SHRLIB) $(LIB) -o pc_advertisement_main
#	$(CC) $(CPPFLAGS) $(INC_PATH) $(LIB_PATH) $(SHRLIB) $(LIB) -Wl,-rpath=$(SHRLIB_PATH) $(OBJS) $(STLIB) pc_advertisement_main.cpp -o $(BIN_PATH)/pc_advertisement_main 
	@printf "\033[32m pc_advertisement_main SUCCESS \033[0m\n"
	
run:
	cd .
	./pc_advertisement_main -c pc_advertisement_server.conf
#	./pc_advertisement_tool_main -c pc_advertisement_client.conf -f PC_Advertisement -q 1111111
	cd $(SRC)
	@printf "\033[32m RUN EXIT!!! \033[0m\n"


clean:
	rm -f *.o
	rm -f pc_advertisement_tool_main
	rm -f pc_advertisement_main
